# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :lock_test.py
# @Time      :2025/7/5 20:34
# @Author    :aiyimu

import threading

shared_resource = 0 # 共享资源
lock = threading.Lock()

# 自增函数
def incr():
    global shared_resource
    for _ in range(10):
        lock.acquire() # 获取锁
        shared_resource += 1
        lock.release() # 释放锁

threads = []
for i in range(5):
    t = threading.Thread(target=incr())
    threads.append(t)
    t.start()

for t in threads:
    t.join()

print(f"最终结果: {shared_resource}")